//
//  ViewController.m
//  17-打电话(系统内置)
//
//  Created by 石虎 on 2017/6/23.
//  Copyright © 2017年 shihu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
//输入手机号
@property (strong, nonatomic) IBOutlet UITextField *phoneTF;
//输入邮箱
@property (strong, nonatomic) IBOutlet UITextField *emailTF;

//打电话
- (IBAction)makePhone:(id)sender;
//发信息
- (IBAction)sendMessage:(id)sender;
//发邮箱
- (IBAction)sendEmail:(id)sender;
//进入网站
- (IBAction)gotoURL:(id)sender;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}
//打电话
- (IBAction)makePhone:(id)sender {
    
    NSString *phoneNum = self.phoneTF.text;
    NSString *urlStr = [NSString stringWithFormat:@"tel://%@",phoneNum];
    NSURL *url = [NSURL URLWithString:urlStr];
    // 调用系统内置应用拨打电话
    [[UIApplication sharedApplication] openURL:url];
}
//发信息
- (IBAction)sendMessage:(id)sender {
    
    NSString *urlStr = [NSString stringWithFormat:@"sms://%@",self.phoneTF.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
//发邮箱
- (IBAction)sendEmail:(id)sender {
    
    NSString *mailStr = [NSString stringWithFormat:@"mailto://%@",self.emailTF.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailStr]];
}
//进入网站
- (IBAction)gotoURL:(id)sender {
    
    NSURL *url = [NSURL URLWithString:self.phoneTF.text];
    [[UIApplication sharedApplication] openURL:url];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}


@end
